]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[St] Implement text-decoration: [underline|strikethrough]
authorColin Walters <walters@verbum.org>
Wed, 2 Dec 2009 19:42:26 +0000 (14:42 -0500)
committerColin Walters <walters@verbum.org>
Fri, 18 Dec 2009 16:20:05 +0000 (11:20 -0500)
Move CSS handling of StLabel and StButton for their underlying
ClutterText objects into st_private, and implement support for
the underline and strikethrough St text-decoration properties.

Overline isn't implemented for lack of a corresponding Pango
attribute, and blink, well...

https://bugzilla.gnome.org/show_bug.cgi?id=599661

src/st/st-button.c
src/st/st-label.c
src/st/st-private.c
src/st/st-private.h

index e1602e0863eb6ea11e514625abe9124e99673563..52032f0f3fc08c1c1fbe5a332261f57c3df98b4c 100644 (file)
@@ -98,10 +98,6 @@ static void
 st_button_update_label_style (StButton *button)
 {
   ClutterActor *label;
-  StThemeNode *theme_node;
-  ClutterColor color;
-  const PangoFontDescription *font;
-  gchar *font_string = NULL;
 
   label = st_bin_get_child ((StBin*) button);
 
@@ -109,15 +105,7 @@ st_button_update_label_style (StButton *button)
   if (!CLUTTER_IS_TEXT (label))
     return;
 
-  theme_node = st_widget_get_theme_node (ST_WIDGET (button));
-
-  st_theme_node_get_foreground_color (theme_node, &color);
-  clutter_text_set_color (CLUTTER_TEXT (label), &color);
-
-  font = st_theme_node_get_font (theme_node);
-  font_string = pango_font_description_to_string (font);
-  clutter_text_set_font_name (CLUTTER_TEXT (label), font_string);
-  g_free (font_string);
+  _st_set_text_from_style ((ClutterText*) label, st_widget_get_theme_node (ST_WIDGET (button)));
 }
 
 static void
index db9b0c1540c24a53480fe48c27ab333d392e10ed..1a304a4bf482428607986f2e9d3ff752994579f2 100644 (file)
@@ -43,7 +43,7 @@
 #include <clutter/clutter.h>
 
 #include "st-label.h"
-
+#include "st-private.h"
 #include "st-widget.h"
 
 enum
@@ -110,21 +110,9 @@ st_label_get_property (GObject    *gobject,
 static void
 st_label_style_changed (StWidget *self)
 {
-  StLabelPrivate *priv;
-  StThemeNode *theme_node;
-  ClutterColor color;
-  const PangoFontDescription *font;
-  gchar *font_string;
-
-  priv = ST_LABEL (self)->priv;
-  theme_node = st_widget_get_theme_node (self);
-  st_theme_node_get_foreground_color (theme_node, &color);
-  clutter_text_set_color (CLUTTER_TEXT (priv->label), &color);
-
-  font = st_theme_node_get_font (theme_node);
-  font_string = pango_font_description_to_string (font);
-  clutter_text_set_font_name (CLUTTER_TEXT (priv->label), font_string);
-  g_free (font_string);
+  StLabelPrivate *priv = ST_LABEL(self)->priv;
+
+  _st_set_text_from_style ((ClutterText *)priv->label, st_widget_get_theme_node (self));
 
   ST_WIDGET_CLASS (st_label_parent_class)->style_changed (self);
 }
index 7332e122abb4421ef7ad1d9698925f339fa1c0ed..182e36de7a06dcfa78847eaf6f255f026f753b10 100644 (file)
@@ -110,3 +110,52 @@ _st_allocate_fill (ClutterActor    *child,
   *childbox = allocation;
 
 }
+
+/**
+ * _st_set_text_from_style:
+ * @text: Target #ClutterText
+ * @theme_node: Source #StThemeNode
+ *
+ * Set various GObject properties of the @text object using
+ * CSS information from @theme_node.
+ */
+void
+_st_set_text_from_style (ClutterText *text,
+                         StThemeNode *theme_node)
+{
+
+  ClutterColor color;
+  StTextDecoration decoration;
+  PangoAttrList *attribs;
+  const PangoFontDescription *font;
+  gchar *font_string;
+
+  st_theme_node_get_foreground_color (theme_node, &color);
+  clutter_text_set_color (text, &color);
+
+  font = st_theme_node_get_font (theme_node);
+  font_string = pango_font_description_to_string (font);
+  clutter_text_set_font_name (text, font_string);
+  g_free (font_string);
+
+  attribs = pango_attr_list_new ();
+
+  decoration = st_theme_node_get_text_decoration (theme_node);
+  if (decoration & ST_TEXT_DECORATION_UNDERLINE)
+    {
+      PangoAttribute *underline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
+      pango_attr_list_insert (attribs, underline);
+    }
+  if (decoration & ST_TEXT_DECORATION_LINE_THROUGH)
+    {
+      PangoAttribute *strikethrough = pango_attr_strikethrough_new (TRUE);
+      pango_attr_list_insert (attribs, strikethrough);
+    }
+  /* Pango doesn't have an equivalent attribute for _OVERLINE, and we deliberately
+   * skip BLINK (for now...)
+   */
+
+  clutter_text_set_attributes (text, attribs);
+
+  pango_attr_list_unref (attribs);
+}
index 34ef85e74d47f0cb2b8ded1bd9700dd74d851c65..42ac82423ff425e816eb8bf59483abdd0f907c16 100644 (file)
@@ -55,4 +55,7 @@ void _st_allocate_fill (ClutterActor    *child,
                         gboolean         x_fill,
                         gboolean         y_fill);
 
+void _st_set_text_from_style (ClutterText *text,
+                              StThemeNode *theme_node);
+
 #endif /* __ST_PRIVATE_H__ */